<%--
  Created by IntelliJ IDEA.
  User: 27716
  Date: 2024/10/30
  Time: 20:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>列表</title>
    <script src="../../static/js/jquery-1.8.2.min.js"></script>
    <link rel="stylesheet" href="../../static/css/css.css">
    <script>
        $(function (){
            let purchaseCode = $("#purchaseCode").val();
            let obj = {purchaseCode:purchaseCode};
            getPurchaseList(obj);
        })
        function getPurchaseList(obj){
            $.ajax({
                url:"/purchase/getPurchaseList",
                type:"post",
                data:{reqInfos:JSON.stringify(obj)},
                dataType:"json",
                success(res){
                    console.log(res);
                    //1.取值 数据 上一页，下一页，尾页
                    let arr = res.list;
                    $("#pageNum").html(res.pageNum)
                    $("#size").html(res.size)
                    $("#pages").html(res.pages)
                    $("#total").html(res.total)
                    $("#table").empty();
                    $("#table").append(`
                    <tr>
                        <td>单据</td>
                        <td>购买单号</td>
                        <td>购物时间</td>
                        <td>购物总数量</td>
                        <td>购物总价</td>
                        <td>购物地址</td>
                        <td>用户id</td>
                        <td>供应商id</td>
                        <td>折扣</td>
                        <td>操作</td>
                    </tr>
                    `)
                    for (let o of arr) {
                        $("#table").append(`
                        <tr>
                                <td>
                                    <input type="checkbox" class="ck" value="\${o.purchaseId}">
                                </td>
                                <td>\${o.purchaseId}</td>0200
                                <td>\${o.purchaseCode}</td>
                                <td>\${o.purchaseTime}</td>
                                <td>\${o.purchaseNum}</td>
                                <td>\${o.purchaseSumprice}</td>
                                <td>\${o.address}</td>
                                <td>\${o.uid}</td>
                                <td>\${o.supplierId}</td>
                                <td>
                                    <input type="button" value="删除" onclick="getToDel(\${o.purchaseId})">
                                    <input type="button" value="修改" onclick="getToUpd(\${o.purchaseId})">
                                </td>

                            </tr>
                        `)
                    }
                    //循环结束之后 追加按钮
                    $("#table").append(`
                        <tr>
                            <td colspan="100">
                                <input type="button" value="首页" onclick="doPage(1)">
                                <input type="button" value="上一页" onclick="doPage(\${res.prePage})">
                                <input type="button" value="下一页" onclick="doPage(\${res.nextPage})">
                                <input type="button" value="尾页" onclick="doPage(\${res.pages})">
                                页数：<input type="text" id="userNum">
                                <input type="button" onclick="page()" value="搜索">
                            </td>
                        </tr>
                    `)
                },
                error(){
                    alert("宝宝出错了");
                }
            })
        }
    </script>
</head>
<body>
名称：<input type="text" id="purchaseCode">
<input type="button" value="搜索" id="search">
    <table id="table">
        <tr>
            <td>单据</td>
            <td>购买单号</td>
            <td>购物时间</td>
            <td>购物总数量</td>
            <td>购物总价</td>
            <td>购物地址</td>
            <td>用户id</td>
            <td>供应商id</td>
            <td>折扣</td>
        </tr>
    </table>
第<span id="pageNum"></span>页   本页<span id="size"></span>条 <span id="pages"></span>页  <span id="total"></span>
</body>
<script>
    function page(){
        let userNum = $("#userNum").val();
        doPage(userNum);
    }
    function search(){
        let purchaseCode = $("#purchaseCode").val();
        let obj = {purchaseCode:purchaseCode};
        getPurchaseList(obj);
    }

    function doPage(pageNum) {

        let purchaseCode = $("#purchaseCode").val();

        let obj = {purchaseCode:purchaseCode,pageNum:pageNum};

        getPurchaseList(obj);
    }
</script>
</html>
